<template>
	<view>
		<view style="font-size:28rpx;line-height:20px;color: #999;padding:20px;">提示：配置参数保存后，前端预计10分钟左右生效。<br>默认为测试广告位，仅在HBuilderX标准基座中有效，仅用于测试，不会产生收益。<br>正式商用替换成你在uniAD后台申请的广告位(adpid)，再自定义基座打包/云打包后生效</view>
		<view class="uni-container" style="float: left;">
			<span>广告位配置</span>
			<uni-forms ref="form" validateTrigger="bind">
				<uni-forms-item label="看视频复活(激励视频广告位)" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="adpid.fuhuoRewardAdpid" style="width: 200px;" />
				</uni-forms-item>
				<uni-forms-item label="做任务看视频(激励视频广告位)" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="adpid.renwuRewardAdpid" style="width: 200px;" />
				</uni-forms-item>
				<uni-forms-item label="拆红包弹框下方(信息流广告位)" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="adpid.hongbaoBannerAdpid" style="width: 200px;" />
				</uni-forms-item>
				<uni-forms-item label="首页插屏广告" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="adpid.interstitialAdpid" style="width: 200px;" />
				</uni-forms-item>
				<uni-forms-item label="微信小程序格子广告广告" name="title" labelWidth="150">
					<input class="uni-input-border" type="number" v-model="adpid.mpGridAdpid" style="width: 200px;" />
				</uni-forms-item>
				<view class="uni-button-group pointer">
					<button class="uni-button uni-button-full" type="primary" :disabled="isLoading"
						@click="save">保存</button>
				</view>
			</uni-forms>
		</view>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				isLoading: false,
				"adpid": {
					"fuhuoRewardAdpid": 0,
					"renwuRewardAdpid": 0,
					"hongbaoBannerAdpid": 0,
					"interstitialAdpid":0,
					"mpGridAdpid":0
				}
			}
		},
		mounted() {
			this.getinfo()
		},
		methods: {
			getinfo() {
				this.isLoading = true
				uni.showLoading({
					title: '加载中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/loadconfig",
						data: {
							id: 'adpid'
						}
					}
				}).then((res) => {
					console.log(res, "get--------------")
					this.adpid = res.result.config
					uni.hideLoading();
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			},
			save() {
				var self = this
				this.isLoading = true
				delete this.adpid._id;
				for (let key in this.adpid) {
					if (key != '_id') {
						this.adpid[key] = Number(this.adpid[key])
					}
				}
				console.log(this.adpid, "-----------")
				uni.showLoading({
					title: '保存中'
				});
				uniCloud.callFunction({
					name: 'uni-admin',
					data: {
						action: "admin/setconfig",
						data: {
							json: JSON.stringify({
								adpid: self.adpid
							})
						}
					}
				}).then((res) => {
					console.log(res, "res--------------")
					this.isLoading = false
					uni.hideLoading();
					uni.showToast({
						title: "修改成功",
						icon: 'none',
						duration: 2000
					})
				}).catch((res) => {
					console.log(res)
				}).finally(err => {
					this.isLoading = false
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>

</style>
